<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>运维单位--发布公告</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Expires" CONTENT="0">
    <meta http-equiv="Cache-Control" content="no-siteapp,no-transform,no-store, no-cache, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <link rel="stylesheet" href="/static/css/buildUnit/common.css">
    <script type="text/javascript" charset="utf-8" src="/lib/utf8-php/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/utf8-php/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/utf8-php/lang/zh-cn/zh-cn.js"></script>
    <style>
        body {
            height: auto;
        }

        .layui-container {
            padding-top: 20px;
            width: auto;
        }

        .v-table .th8 {
            width: 6rem;
            min-width: 6rem;
        }

        .layui-table td {
            padding: 3px 15px;
        }

        #editor {
            width: 720px;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <form id="form" class="layui-form layui-form-pane" action="" lay-filter="example">
        <table class="layui-table v-table">
            <tbody>
            <tr>
                <td class="th8 required">标题</td>
                <td>
                    <input type="text" name="noticeTitle" lay-verify="isEmpty" placeholder="请输入"
                           autocomplete="off"
                           class="layui-input formData noticeTitle">
                </td>
            </tr>
            <tr>
                <td class="th8 required" style="vertical-align: text-top;">内容</td>
                <td style="height:180px;">
                    <script type="text/html" id="editor"></script>
                </td>
            </tr>
            <tr>
                <td class="th8 required">接收单位</td>
                <td id="acceptOrgType">

                </td>
            </tr>
            <tr>
                <td class="th8">是否弹窗提示</td>
                <td>
                    <input type="checkbox" class="tipsFlag formData" name="tipsFlag" value="0"
                           lay-filter="tipsFlag" id="tipsFlag"
                           title="提示">
                </td>
            </tr>
            </tbody>
        </table>
        <button lay-submit lay-filter="submit" style="display: none;" id="submit" class="submit">提交</button>
    </form>
</div>
<script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
<script src="/static/js/main.js"></script>
<script type="text/javascript">
    var window = '';
    var noticeContent;//编辑内容
    layui.use(['jquery',  'form', 'table', 'configure', 'configureCom', 'bluebird'], function () {
        var form = layui.form;
        var configure = layui.configure;
        var configureCom = layui.configureCom;
        var sessionFun = layui.sessionFun;
        window.$ = layui.jquery;
        var Notice = sessionFun.get(configure.SESSION_NOTICE_LIST_DATA);
        configureCom.checkboxDataFun(configure.NOTICE_ORG_TYPE, '', 'acceptOrgType'); //接收单位
        window.ue = UE.getEditor('editor');//实例化编辑器
        ue.ready(function () {
            //查看或编辑时 初始化表单赋值
            if (Notice) {
                $('.noticeTitle').val(Notice.noticeTitle);//标题
                setContent(Notice.noticeContent);//内容
                configureCom.checkboxDataFun(configure.NOTICE_ORG_TYPE, Notice.acceptOrgType, 'acceptOrgType'); //接收单位
                if (Notice.tipsFlag == 0) {//是否提示
                    $("input.tipsFlag").attr('checked', 'checked');
                }
                form.render();
            }
        });
        window.setContent = function (html) {
            ue.setContent(html);
        };
        var unionRecordArr = [];
        //监听选择接收单位
        form.on('checkbox(acceptOrgType)', function (data) {
            if (data.elem.checked) {
                var checkBox = $(data.elem).parent().find('[type="checkbox"]:checked');
                $(checkBox).each(function (index, item) {
                    unionRecordArr.push($(item).val());
                });
                if (unionRecordArr.indexOf('10') > -1) {//选择不限
                    $('input[value !="10"]').removeAttr('checked');
                    form.render();
                }
                /*if (unionRecordArr.indexOf('10') > 0) {//不选不限
                    $('input[value="10"]').removeAttr('checked');
                }*/
            }

        });
        form.on('submit(submit)', function (data) {
            noticeContent = data.field.editorValue;//赋值内容
            var res = {};
            res.noticeTitle = data.field.noticeTitle;
            if (!UE.getEditor('editor').hasContents()) {
                top.layer.msg('请输入通知内容');
                return false;
            }
            if (unionRecordArr.length == 0) {
                top.layer.msg('请选择接收单位');
                return false;
            }
            return false;
        });
    });

    function getData() {
        return new Promise(function (res, rej) {
            var data = {};
            if (!window.formVerifyFun()) {
                return false;
            }
            $('.formData').each(function (index, item) {
                if (!($(item).closest('tr').hasClass('hide'))) {
                    var key = '';
                    if ($(item).attr('type') == 'checkbox') {
                        key = $(item).attr('name');
                        var value = '';
                        $('[name="' + key + '"]:checked').each(function (index, item) {
                            if (!index) {
                                value = $(item).val();
                            } else {
                                value += ',' + $(item).val();
                            }
                        });
                        data[key] = value;
                        data.noticeContent = noticeContent;
                    } else {
                        key = $(item).attr('name');
                        data[key] = $(item).val();
                    }
                }
            });
            res({result: data});
        });
    }

</script>
</body>
</html>
